import request from '@/config/axios'

export interface DeviceVO {
  id: number
  assetId: number
  assetName: string
  assetBrand: string
  assetModel: string
  location: string
  deviceStatus: number
  assetSn: string
}

// 查询设备管理列表
export const getDevicePage = (params: PageParam) => {
  return request.get({ url: '/bms/device/page', params })
}

// 查询所有设备列表
export const getAllDevice = () => {
  return request.get({ url: '/bms/device/all' })
}

// 查询设备详情
export const getDevice = (id: number) => {
  return request.get({ url: '/bms/device/get?id=' + id })
}

// 新增设备
export const createDevice = (data: DeviceVO) => {
  return request.post({ url: '/bms/device/create', data })
}

// 修改设备
export const updateDevice = (data: DeviceVO) => {
  return request.put({ url: '/bms/device/update', data })
}

// 删除设备
export const deleteDevice = (id: number) => {
  return request.delete({ url: '/bms/device/delete?id=' + id })
}

// 设备状态修改
export const updateDeviceStatus = (id: number, deviceStatus: number) => {
  const data = {
    id,
    deviceStatus
  }
  return request.put({ url: '/bms/device/update-status', data: data })
}

// 获取设备精简信息列表
export const getSimpleDeviceList = (): Promise<DeviceVO[]> => {
  return request.get({ url: '/bms/device/simple-list' })
}

// 获取设备精简信息列表
export const syncAsset = () => {
  return request.get({ url: '/bms/device/sync-asset' })
}

// 保存配件列表
export const saveFittingsBindDevice = (data) => {
  return request.post({ url: '/bms/device/saveFittings', data })
}
